﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegexJson.Common;
namespace RegexJson
{

    public partial class Form2 : Form
    {
        List<KeyWordInfo> qpList = new List<KeyWordInfo>();
        KeyWordSearch keyWordSearch = null;
        public Form2()
        {
            InitializeComponent();
           
        }

        private void btn_Start_Click(object sender, EventArgs e)
        {
            string strTemp = tbContent.Text;
            string[] strs = strTemp.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            btn_Start.Enabled = false;
            foreach (string str in strs)
            {
                KeyWordInfo keword = new KeyWordInfo();
                keword.KeyWord = str;
                qpList.Add(keword);
            }
            if (keyWordSearch == null)
            {
                keyWordSearch = new KeyWordSearch(qpList);
                keyWordSearch.KeyWordSearchHandle += new KeyWordSearch.KeyWordSearchEventHandle(keyWordSearchUpdate);
            }
            keyWordSearch.Start();
        }
        

        private void keyWordSearchUpdate(object sender, KeyWordSearchArgs e)
        {
            this.Invoke((EventHandler)delegate
              {
                  DataGridViewRow dr = new DataGridViewRow();
                  dr.CreateCells(dataGridView1);
                  dr.Cells[0].Value = e.KeyWord;
                  dr.Cells[1].Value = e.JingJiaNum;
                  dr.Cells[2].Value = e.BaiduIndexNum;
                  dr.Cells[3].Value = e.GoogleIndexNum;
                  dataGridView1.Rows.Add(dr);
              });
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            
        }

        private void Form2_Load(object sender, EventArgs e)
        {
                  
        }
    }
}
